package switchviz.core.view;


import java.awt.Dimension;
import java.awt.event.ActionListener;
import java.awt.event.ItemListener;

import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.event.ChangeListener;


import switchviz.core.ResourceManager;
import switchviz.gui.component.JLabeldComponent;
import switchviz.gui.component.PaddingPanel;
import switchviz.gui.component.SlidePanel;

public class ViewStatePanel extends PaddingPanel
{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1771979901305911268L;
	private SlidePanel _slpanel = null;
	private JButton _saveview = null;
	private JButton _saveviewas = null;
	private JButton _buttlegend = null;
	private JLabel _lblname = null;
	private JLabeldComponent _checkNotConnected = null;
	
	public ViewStatePanel()
	{
		initialize();
	}
	
	public void setViewName(String name)
	{
		_lblname.setText(name);
	}
	
	public void setSlider(int value)
	{
		_slpanel.getSlider().setValue(value);
	}
	
	public void addChangeListener(ChangeListener l)
	{
		_slpanel.getSlider().addChangeListener(l);
	}
	
	public void addActionListener(ActionListener l)
	{
		_saveview.addActionListener(l);
		_saveviewas.addActionListener(l);
		_buttlegend.addActionListener(l);
	}
	
	public void addItemListener(ItemListener l)
	{
		_checkNotConnected.getCheckBox().addItemListener(l);
	}
	
	private void initialize()
	{
		Dimension labelwidth = new Dimension(200, 20);
		this.setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
		this.setBorder(BorderFactory.createTitledBorder("View Information and State"));
		_slpanel = new SlidePanel("Render Rate (FPS): ", 0, 60, 30);
		_saveview = new JButton("Save View");
		_saveview.setActionCommand(ResourceManager.getInstance().getActionSaveView());
		_saveviewas = new JButton("Save View As");
		_saveviewas.setActionCommand(ResourceManager.getInstance().getActionSaveViewAs());
		_buttlegend = new JButton("Open Legend");
		_buttlegend.setActionCommand(ResourceManager.getInstance().getActionNew());
		_lblname = new JLabel();
		_checkNotConnected = new JLabeldComponent("Display not Connected Ports: ", JLabeldComponent.CHECKBOX, labelwidth);
		_checkNotConnected.getCheckBox().setSelected(true);
		
        JPanel buttonpanel = new JPanel();
        buttonpanel.setLayout(new BoxLayout(buttonpanel, BoxLayout.LINE_AXIS));
        buttonpanel.add(Box.createHorizontalGlue());
        buttonpanel.add(_saveview);
        buttonpanel.add(_saveviewas);
        
        JPanel legendpanel = new JPanel();
        legendpanel.setLayout(new BoxLayout(legendpanel, BoxLayout.LINE_AXIS));
        legendpanel.add(Box.createHorizontalGlue());
        legendpanel.add(_buttlegend);
		
		this.add(_lblname);
		this.add(Box.createRigidArea(ResourceManager.getInstance().getConfigurationLabelDimension()));
		this.add(_slpanel);
		this.add(_checkNotConnected);
		this.add(buttonpanel);
		this.add(legendpanel);
	}
}
